let fs = require("fs")//引入fs模块
let express = require("express")
var app = express()
const bodyParser = require("body-parser")
app.use(bodyParser.urlencoded({ extended: false }))//解析表单数据
app.use(bodyParser.json())//解析json数据
// 获取所有数据
var all_book = fs.readFileSync("./book.json")
all_book = all_book.toString()
all_book = JSON.parse(all_book)
// 中间件
app.use((req, res, next) => {
    res.setHeader('Content-Type', 'text/html;charset=utf-8')
    res.setHeader('Access-Control-Allow-Origin', "*")
    next()
})
app.get('/users', (req, res) => {
    res.json({
        code: 0,
        msg: '请求成功',
        data: all_book

    })
})
app.listen(3000, () => {
    console.log('启动服务: http://127.0.0.1:3000');

})
